'''
Created on Jun 20, 2012

@author: alebalbin
'''
from collections import defaultdict
#from base import gtf_transcript


class gtf_transcript():
            
    def __init__(self,fields):
        '''
        transcript_id
        need to modify the parser for the predict transcripts:
            the self.annotation should include at least the following keys
                ft="transcript_id"
                ftn="transcript_name"
                ftb="gene_biotype"
        '''
        self.annotation=defaultdict()
        self.chrom=fields[0]
        self.feature=fields[1]
        self.feature_type=fields[2]
        self.start=int(fields[3])
        self.end=int(fields[4])
        self.atributte1=fields[5]
        self.strand=fields[6]
        self.atribute2=fields[7]
        for a in fields[-1].split(';'):
            if a=='':
                continue
            att, value= a.split()[0].strip(),a.split()[1].strip()
            self.annotation[att]=value.strip('\"')
        return
        
    
def read_gtf(gtf_file):
    for line in gtf_file:
        fields = line.strip('\n').split('\t')
        yield gtf_transcript(fields)